﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using VAdvantage.DataBase;
using ViennaAdvantage.Model;
using VAdvantage.Utility;


namespace VAdvantageWeb
{
    public partial class CampaignInvitee : System.Web.UI.Page
    {

        # region Private Variables
        string sql = "";
        int C_InviteeList_ID = 0;
        string txt = "";
        string color = "";
        string Header = "";
        string Footer = "";
        string formColor = "";
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            string url = HttpContext.Current.Request.Url.ToString();
            sql = "select c_inviteelist_id from c_inviteelist where url = '" + url + "'";
            int C_InviteeList_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
            if (C_InviteeList_ID != 0)
            {
                sql = "SELECT c_campaigntemplate_id FROM c_campaign where c_campaign_id = (select C_Campaign_id from c_inviteelist where c_inviteelist_id = " + C_InviteeList_ID + ")";
                int C_CTemplate_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                if (C_CTemplate_ID != 0)
                {
                    sql = "select * from c_campaigntemplate where c_campaigntemplate_id = " + C_CTemplate_ID;
                    DataSet ds = DB.ExecuteDataset(sql, null, null);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {

                            txt = Util.GetValueOfString(ds.Tables[0].Rows[0]["HtmlText"]);
                            IBackInt obj = Master as IBackInt;
                            obj.HTML = txt;

                            Header = Util.GetValueOfString(ds.Tables[0].Rows[0]["HeaderHtml"]);
                            obj.Header = Header;
                            Footer = Util.GetValueOfString(ds.Tables[0].Rows[0]["FooterHtml"]);
                            obj.Footer = Footer;

                            int AD_PrintColor_ID = Util.GetValueOfInt(ds.Tables[0].Rows[0]["AD_PrintColor_ID"]);

                            sql = "select Code from AD_PrintColor where AD_PrintColor_ID = " + AD_PrintColor_ID;
                            string colorCode = Util.GetValueOfString(DB.ExecuteScalar(sql, null, null));

                            color = "<style type= " + "text/css" + ">"
                                + " http://dl.dropbox.com/u/61344829/lp_joom/images/style.css "     
                                + " .st"
                                       + " {"
                                 + " background: " + colorCode + ";"
                                //      + " background-image: url('" + System.Web.VirtualPathUtility.ToAbsolute("~/Images/Penguins.jpg") + "'); "
                                // + "  font-size: .80em;"
                                // +" font-family: "Helvetica Neue" , "Lucida Grande" , "Segoe UI" , Arial, Helvetica, Verdana, sans-serif;"
                                       + " margin: 0;"
                                       + " padding: 0;"
                                      + " position:absolute; "
                                       + " z-index:0; "
                                       + " left:0px; top:0px; "
                                       + " width:100%; "
                                       + " height:auto; "
                                //+ " color: #000033; "
                                       + " }"
                                       + " </style>";
                            obj.BackColor = color;


                            //color = "<style type= " + "text/css" + ">"
                            //            + " .styleform"
                            //            + " {"
                            //            + " position:absolute; "
                            //            + " z-index:0; "
                            //            + " left:0px; top:0px; "
                            //            + " width:100%; "
                            //            + " height:100%; "
                            //            + " background-image: url('" + System.Web.VirtualPathUtility.ToAbsolute("~/Images/Penguins.jpg") + "'); "
                            //            + " background-size: 100%; "
                            //            // + " background-repeat: no-repeat; "
                            //            + " margin: 0px;"
                            //            + " padding: 0px;"
                            //    //  + " height: 900px;"
                            //            + " }"
                            //            + " </style>";
                            //obj.BackColor = color;

                            int Ref_AD_PrintColor_ID = Util.GetValueOfInt(ds.Tables[0].Rows[0]["Ref_AD_PrintColor_ID"]);

                            sql = "select Code from AD_PrintColor where AD_PrintColor_ID = " + Ref_AD_PrintColor_ID;
                            string formColorCode = Util.GetValueOfString(DB.ExecuteScalar(sql, null, null));

                            formColor = "<style type= " + "text/css" + ">"
                                      + " .formBackColor"
                                      + " {"
                                + " background: " + formColorCode + ";"
                                      + " }"
                                      + " </style>";
                            obj.FormBackColor = formColor;
                        }
                    }
                }
            }

            if (!IsPostBack)
            {
                sql = "select name, value from ad_ref_list where ad_reference_id = 1000097";
                DataSet ds = DB.ExecuteDataset(sql, null, null);
                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        ddlResponse.DataSource = ds.Tables[0];
                        ddlResponse.DataValueField = "VALUE";
                        ddlResponse.DataTextField = "NAME";
                        ddlResponse.DataBind();
                        ddlResponse.SelectedIndex = -1;
                    }
                }
                if (C_InviteeList_ID != 0)
                {
                    url = HttpContext.Current.Request.Url.ToString();
                    sql = "select Remark from c_inviteelist where url = '" + url + "'";
                    string Remark = Util.GetValueOfString(DB.ExecuteScalar(sql, null, null));
                    txtRemarks.Text = Remark;
                    sql = "select inviteeresponse from c_inviteelist where url = '" + url + "'";
                    string resp = Util.GetValueOfString(DB.ExecuteScalar(sql, null, null));
                    if (resp != "")
                    {
                        ddlResponse.SelectedValue = resp;
                    }
                }

                //Random r = new Random();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string url = HttpContext.Current.Request.Url.ToString();
                sql = "select c_inviteelist_id from c_inviteelist where url = '" + url + "'";
                int C_Inviteelist_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                if (C_Inviteelist_ID != 0)
                {
                    DateTime? today = System.DateTime.Now;
                    string value = ddlResponse.SelectedValue;
                    sql = "update c_inviteelist set responsedate  = " + DB.TO_DATE(today, false) + " , remark = '" + txtRemarks.Text + "', INVITEERESPONSE = '" + value + "'  where c_inviteelist_id = " + C_Inviteelist_ID;
                    int res = DB.ExecuteQuery(sql, null, null);
                }
              //  Response.Write("<script language='javascript'>alert('Response Submitted Successfully!');</script>");
            }
            catch
            {

            }
        }

    }
}